package com.myblog.myblog.controller;

import com.myblog.myblog.domain.TaskJob;
import com.myblog.myblog.service.TaskJobService;
import com.myblog.myblog.utils.ResultData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author gyl
 * @data 2020/5/5 16:33
 */
@RestController
@RequestMapping("taskJob")
public class TaskJobController {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    TaskJobService taskJobService;

    @PostMapping(value = "/addTaskJob")
    @ResponseBody
    public ResultData addTaskJob(@RequestBody TaskJob taskJob){
        taskJobService.save(taskJob);
        return ResultData.success();
    }

    @PostMapping(value = "/updateaskJob")
    @ResponseBody
    public ResultData updateaskJob(@RequestBody TaskJob taskJob){
        taskJobService.update(taskJob);
        return ResultData.success();
    }

    @PostMapping(value = "/runTask")
    @ResponseBody
    public ResultData runTask(String jobId){
        taskJobService.run(jobId);
        return ResultData.success();
    }

    @PostMapping(value = "/pauseTask")
    @ResponseBody
    public ResultData pause(@RequestBody() String jobId){
        taskJobService.pause(jobId);
        return ResultData.success();
    }

    @PostMapping(value = "/resumeTask")
    @ResponseBody
    public ResultData resume(@RequestBody() String jobId){
        taskJobService.resume(jobId);
        return ResultData.success();
    }


}